﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Sgml.Configuration;
using System.Diagnostics;

namespace Engine.Sgml.Validation {
    /// <summary>
    /// Used when 'PreserveWhiteSpace' option is disabled.
    /// </summary>
    internal sealed class IgnoreWhiteSpaceValidator : IElementValidator {

        public SElement Validate(SElement element, SElement node) {
            Debug.Assert(node.LastNode.NodeType == SgmlNodeType.WhiteSpace);
            Debug.Assert(element.NodeType == SgmlNodeType.WhiteSpace);

            if (node.HasDeclaration && (node.Declaration.ContentModel.Mixed || node.Declaration.ContentModel.TextOnly)) {
                element.NodeType = SgmlNodeType.SignificantWhiteSpace;
                return node;
                }
            else {
                node.Nodes.Pop();
                return node;
                }
            }
        }
    }
